<?php
/**
 * 系统设置控制器
 * UserModel: LLw
 * Data: 2020-2-12
 * Tiem: 17:57
 */
namespace app\caidongweb\controller;

use app\caidongweb\model\LogsModel;

class Config extends BaseController
{
    /**
     * 首页信息
     * @return array|\think\response\View
     */
    public function index()
    {
        $data = input('post.');
        if($data){
            if($data['type'] == 1){
                unset($data['headImg']);
                if($data['State'] == 0){
                    if($data['Nodesc'] == ''){
                        return $this->returnData(-1,'请填写网站关闭原因');
                    }
                }
            }
            unset($data['type']);
            foreach ($data as $k=>$v){
                db('config')->where('gc_title',$k)->setField('gc_value',$v);
            }
            return array('code'=>1,'msg'=>'成功');
        }else{
            $this->assign('Worig',tpConfig('Worig'));//系统收款钱包地址
            $this->assign('Kfei',tpConfig('Kfei'));//提现矿工费
            $this->assign('Gwei',tpConfig('Gwei'));//首页广告
            $this->assign('Kfei',tpConfig('Kfei'));//提币矿工费率
            $this->assign('Poins',tpConfig('Poins'));//1U等于多少蔬菜积分
            $this->assign('Mci',tpConfig('Mci'));//报单USDT额度
            $this->assign('share',tpConfig('share'));//分享奖
            $this->assign('static',tpConfig('static'));//静态收益比例
            $this->assign('reborn_one',tpConfig('reborn_one'));//止损重生第1期返回波比
            $this->assign('reborn_two',tpConfig('reborn_two'));//止损重生第2期返回波比
            $this->assign('reborn_three',tpConfig('reborn_three'));//止损重生第3期返回波比
            $this->assign('reborn_four',tpConfig('reborn_four'));//止损重生第4期返回波比
            $this->assign('Aimg',tpConfig('Aimg'));//系统收款码
            $this->assign('Logo',tpConfig('Logo'));//网站LOGO
            $this->assign('XiZhi',tpConfig('XiZhi'));//系统通知
            $this->assign('Nodesc',tpConfig('Nodesc'));//网站关闭原因
            $this->assign('State',tpConfig('State'));//网站状态
            $this->assign('Title',tpConfig('Title'));//网站标题
            $this->assign('Bei',tpConfig('Bei'));//网站备案号
            $this->assign('Daima',tpConfig('Daima'));//统计代码
            $this->assign('Ban',tpConfig('Ban'));//版权信息
            return view();
        }
    }

    /**
     * 图片上传
     * @return array
     */
    public function upload()
    {
        $file = \request()->file('file');
        $newname = time();
        $path = 'uploads/config/';
        if(!file_exists($path)){
            mkdir($path,777);
        }
        $saveInfo = $file->validate(['size'=>1567800,'ext'=>'jpg,png,gif'])->move($path,$newname);
        if($saveInfo){
            $pathInfo = '/'.$path.$saveInfo->getSaveName();
            db('config')->where('gc_title','Logo')->setField('gc_value',$pathInfo);
            return ['code'=>1,'msg'=>'上传成功','src'=>$pathInfo];
        }else{
            return ['code'=>-1,'msg'=>'上传失败'];
        }
    }

    /**
     * 图片上传2
     * @return array
     */
    public function uploads()
    {
        $file = \request()->file('file');
        $newname = time();
        $path = 'uploads/config/';
        if(!file_exists($path)){
            mkdir($path,777);
        }
        $saveInfo = $file->validate(['size'=>1567800,'ext'=>'jpg,png,gif'])->move($path,$newname);
        if($saveInfo){
            $pathInfo = '/'.$path.$saveInfo->getSaveName();
            db('config')->where('gc_title','Aimg')->setField('gc_value',$pathInfo);
            return ['code'=>1,'msg'=>'上传成功','src'=>$pathInfo];
        }else{
            return ['code'=>-1,'msg'=>'上传失败'];
        }
    }

    /**
     * 管理员操作日志
     * @return \think\response\View
     */
    public function logs()
    {
        $log = new LogsModel();
        $list = $log->getUserList();
        $this->assign('list',$list);
        $this->assign('page',$list->render());
        return view();
    }

    /**
     * 删除消息
     * @return array
     */
    public function logsDel()
    {
        $id = input('id');
        $res = $this->del('logs',['lo_id'=>$id]);
        if($res){
            return $this->returnData(1,'成功');
        }
        return $this->returnData(-1,'失败');
    }
}
